package com.aegean.MonitorExamSYS.conduction.businessImpl;

import java.io.File;
import java.io.InputStream;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.aegean.MonitorExamSYS.conduction.business.ConductionBusiness;
import com.aegean.MonitorExamSYS.conduction.component.PositionsInfo;
import com.aegean.MonitorExamSYS.conduction.dao.ConductionDao;
import com.aegean.MonitorExaxSYS.model.BigType;
import com.aegean.MonitorExaxSYS.model.ConductionValue;
import com.aegean.MonitorExaxSYS.model.ExamPosition;
import com.aegean.MonitorExaxSYS.model.MessageBox;
import com.aegean.MonitorExaxSYS.model.MonitorValue;
import com.aegean.MonitorExaxSYS.model.SmallType;

@Service
@Transactional
public class ConductionBusinessImpl implements ConductionBusiness {
	@Resource
	ConductionDao dao;

	@Override
	public ConductionValue insertConduction(ConductionValue one) {
		// TODO Auto-generated method stub
		return dao.insertConduction(one);
	}

	@Override
	public boolean insertExamPosition(ExamPosition one,
			ConductionValue conduction) {
		// TODO Auto-generated method stub
		return dao.insertExamPosition(one, conduction);
	}

	@Override
	public ConductionValue loginConduction(String login, String pwd) {
		// TODO Auto-generated method stub
		return dao.loginConduction(login, pwd);
	}

	@Override
	public int examPositionCount(int Conduction_Id) {
		// TODO Auto-generated method stub
		return dao.examPositionCount(Conduction_Id);
	}

	@Override
	public List<ExamPosition> ShowExamPositions(int start, int limit,
			int Conduction_Id) {
		// TODO Auto-generated method stub
		return dao.ShowExamPositions(start, limit, Conduction_Id);
	}

	@Override
	public boolean editExamPosition(ExamPosition one, int examPosition_Id) {
		// TODO Auto-generated method stub
		return dao.editExamPosition(one, examPosition_Id);
	}

	@Override
	public boolean deleteExamPositions(int[] examPosition_Id) {
		// TODO Auto-generated method stub
		return dao.deleteExamPositions(examPosition_Id);
	}

	@Override
	public int examPositionCountQuery(String query, int Conduction_Id) {
		// TODO Auto-generated method stub
		return dao.examPositionCountQuery(query, Conduction_Id);
	}

	@Override
	public List<ExamPosition> ShowExamPositionsQuery(String query, int start,
			int limit, int Conduction_Id) {
		// TODO Auto-generated method stub
		return dao.ShowExamPositionsQuery(query, start, limit, Conduction_Id);
	}

	@Override
	public int monitorListCount(int Conduction_Id, int search_Id, int big_Id,
			int state, String query) {
		// TODO Auto-generated method stub
		DetachedCriteria dcr = DetachedCriteria.forClass(MonitorValue.class);
		if (search_Id == 0) {
			/* 查找没有通过填写查询信息监考人员 */
			if (big_Id == 0) {
				if (state == 0) {
					dcr.add(Restrictions.eq("monitor_State", 1));// 查询所有已经审批的监考人员
				} else {
					dcr.add(Restrictions.eq("monitor_State", 0));// 查询所有未审批但是申请的监考人员
				}
			} else {
				/* 根据专业查找已经审批的监考人员 */
				dcr.add(Restrictions.eq("monitor_State", 1));
				dcr.add(Restrictions.eq("monitor_Big.big_Id", big_Id));
			}
		} else {
			/* 查找通过填写查询信息进行查找的已经审批的监考人员 */
			if (search_Id == 1) {
				/* 根据姓名查找 */
				dcr.add(Restrictions.like("user_RealName", "%" + query + "%"));
			} else {
				/*根据员工号*/
                dcr.add(Restrictions.like("monitor_Identity", "%" + query + "%"));
			}
		}
		dcr.add(Restrictions.eq("monitor_Unit.conduction_Id", Conduction_Id));
		return dao.monitorListCount(dcr);
	}

	@Override
	public List<MonitorValue> ShowMonitorListQuery(int Conduction_Id,
			int search_Id, int big_Id, int state, String query, int start,
			int limit) {
		// TODO Auto-generated method stub
		DetachedCriteria dcr = DetachedCriteria.forClass(MonitorValue.class);
		if (search_Id == 0) {
			/* 查找没有通过填写查询信息监考人员 */
			//System.out.println("/* 查找没有通过填写查询信息监考人员 */");
			if (big_Id == 0) {
				if (state != 0) {
					//System.out.println("// 查询所有已经审批的监考人员");
					dcr.add(Restrictions.eq("monitor_State", 1));// 查询所有已经审批的监考人员
				} else {
					// 查询所有未审批但是申请的监考人员
					//System.out.println("// 查询所有未审批但是申请的监考人员");
					dcr.add(Restrictions.eq("monitor_State", 0));// 查询所有未审批但是申请的监考人员
				}
			} else {
				/* 根据专业查找已经审批的监考人员 */
				//System.out.println("/* 根据专业查找已经审批的监考人员 */");
				dcr.add(Restrictions.eq("monitor_State", 1));
				dcr.add(Restrictions.eq("monitor_Big.big_Id", big_Id));
			}
		} else {
			/* 查找通过填写查询信息进行查找的已经审批的监考人员 */
			//System.out.println("	/* 查找通过填写查询信息进行查找的已经审批的监考人员 */");
			if (search_Id == 1) {
				/* 根据姓名查找 */
				//System.out.println("/* 根据姓名查找 */");
				dcr.add(Restrictions.like("user_RealName", "%" + query + "%"));
			} else {
				/*根据员工号*/
				//System.out.println("/*根据员工号*/");
                dcr.add(Restrictions.like("monitor_Identity", "%" + query + "%"));
			}
		}
		dcr.add(Restrictions.eq("monitor_Unit.conduction_Id", Conduction_Id));
		return dao.ShowMonitorListQuery(dcr,start,limit);
	}

	@Override
	public int bigListCount() {
		// TODO Auto-generated method stub
		return dao.bigListCount();
	}

	@Override
	public List<BigType> bigList(int start, int limit) {
		// TODO Auto-generated method stub
		return dao.bigList(start, limit);
	}

	@Override
	public boolean addMonitorValue(MonitorValue monitor,int big_Id) {
		// TODO Auto-generated method stub
		return dao.addMonitorValue(monitor,big_Id);
	}

	@Override
	public MonitorValue showMonitorPhoto(int monitor_Id) {
		// TODO Auto-generated method stub
		return dao.showMonitorPhoto(monitor_Id);
	}

	@Override
	public boolean passedState(int state, int[] monitor_Ids) {
		// TODO Auto-generated method stub
		return dao.editState(state, monitor_Ids);
	}

	@Override
	public boolean defuseState(int state, int[] monitor_Ids) {
		// TODO Auto-generated method stub
		return dao.editState(state, monitor_Ids);
	}

	@Override
	public int smallListCount(int small_Id) {
		// TODO Auto-generated method stub
		return dao.smallListCount(small_Id);
	}

	@Override
	public List<SmallType> SmallList(int start, int limit, int small_Id) {
		// TODO Auto-generated method stub
		return dao.SmallList(start, limit, small_Id);
	}

	@Override
	public boolean applyForQualification(int state, int Conduction_Id,
			int exam_Id) {
		// TODO Auto-generated method stub
		return dao.applyForQualification(state, Conduction_Id, exam_Id);
	}

	@Override
	public boolean writeMessage(int conduction_Id, String theme, String contents) {
		// TODO Auto-generated method stub
		return dao.writeMessage(conduction_Id, theme, contents);
	}

	@Override
	public List<MessageBox> showMessages(int state, int status,
			int conduction_Id, int start, int limit) {
		// TODO Auto-generated method stub
		return dao.showMessages(state, status, conduction_Id, start, limit);
	}

	@Override
	public boolean replyMessage(int conduction_Id, String theme,
			String contents, int beforeId) {
		// TODO Auto-generated method stub
		return dao.replyMessage(conduction_Id, theme, contents, beforeId);
	}

	@Override
	public List<PositionsInfo> showPositions(int big_Id, int condu) {
		// TODO Auto-generated method stub
		return dao.showPositions(big_Id, condu);
	}

}
